<?php defined('SYS_PATH') or die('No direct script access.');

class IndexController extends Controller
{
    public function indexAction()
    {
        echo 'Hello TrueBlood@' . time();
    }

    public function viewAction()
    {
        $tpl = 'user';
        $vars = array('username' => 'zendzhang', 'password' => 123456);

        $this->view($tpl, $vars);
    }

    public function dbAction()
    {
        // Get model
        $model = $this->model('user');

        // Insert
        $insert = array('username' => 'zendzhang', 'password' => 123456);
        $userid = $model->insert($insert);

        // Select
        $user = $model->select($userid);var_dump($user);

        // Update
        $update = array('password' => '654321');
        $where = array('username' => 'zendzhang');
        $boolean = $model->update($update, $where);

        // Delete
        $rows = $model->delete($where);
    }

    public function mcAction()
    {
        $key = 'Hello'; $value = 'TrueBlood';

        // Set
        $this->mc->set($key, $value);

        // Get
        $data = $this->mc->get($key);var_dump($data);

        // Del
        $data = $this->mc->del($key);
    }

    public function httpAction()
    {
        // Get
        echo $this->http->get("http://www.soso.com")->body;

        // Post
        $data = array('u' => 'zendzhang', 'p' => '123456');
        echo $this->http->post("http://ptlogin2.soso.com/login", $data)->body;
    }

    public function cookieAction()
    {
        $key = 'Hello'; $value = 'TrueBlood';

        // Set
        $this->cookie->set($key, $value);

        // Get
        $data = $this->cookie->get($key); var_dump($data);

        // Del
        $this->cookie->del($key);
    }

    public function logAction()
    {
        // Error
        $this->log('error', 'error message');

        // Debug
        $this->log('debug', 'debug message');

        // Info
        $this->log('info', 'test info');
    }
}
